<div class="row">
  <div class="col-md-12">

    <div id="content_header">
      <h3>Register a new Student Discounts</h3>
    </div>

    <div class="row" ng-hide="item.Student.Id">
      <div class="col-md-6 col-lg-6">
        <form role="form" ng-submit="searchStudent()">
          <div class="form-group">
            <div class="input-group">
              <input type="text" class="form-control" id="" placeholder="Input Student ID or Student Name and press enter to search" ng-model="searchText">
              <span class="input-group-btn">
                <button type="submit" class="btn btn-primary"><i class="simple-icon-magnifier"></i> Search</button>
              </span>
            </div>
          </div>
        </form>
        
      </div>
    </div>

    <!-- RESULTS BY SEARCHING STUDENT NAME / SID  -->
    <div class="row" ng-if="students.length > 0" ng-hide="item.Student.Id">
      <div class="col-md-12">
        <table class="table table-hover">
          <thead>
            <tr>
              <th>Name</th>
              <th>SID</th>
              <th>Discount</th>
            </tr>
          </thead>
          <tbody>
            <tr dir-paginate="student in students | itemsPerPage: pagesize" total-items="totalItems">
              <td>
                <span class="dropdown">
                  <a href class="dropdown-toggle" ng-bind-html="student.FullName | makeBold:searchKey"></a>
                  <ul class="dropdown-menu">
                    <!-- <li role="presentation" class="dropdown-header">Action</li> -->
                    <li ng-if="!student.PlacementTest"><a href ng-click="selectStudent(student.Id)">Register to PT</a></li>
                  </ul>
                </span>
              </td>
              <td ng-bind-html="student.SID | makeBold:searchKey"></td>
              <td>
                <a href ng-click="selectStudent(student.Id)">Manage Discount</a>
              </td>
            </tr>
          </tbody>
        </table>
        <dir-pagination-controls on-page-change="pageChanged(newPageNumber)" template-url="views/templates/dirPagination.tpl.html"></dir-pagination-controls>
        
      </div>
    </div>

    <div class="row" ng-show="item.Student.Id">
      <div class="col-md-12 col-lg-4">
        <form name="Form" role="form" ng-submit="add()">

          <div class="form-group">
            <label for="">Student</label>
            <span class="form-control">{{ currStudent.FullName }} <small><a href="" ng-click="resetStudent()">Change Student</a></small></span>
          </div>

          <div class="form-group">
            <label for="DiscountType">Discount Type</label>
            <select name="DiscountType" id="DiscountType" class="form-control" ng-options="type as type.Name for type in DiscountTypes" ng-model="item.DiscountType" ng-change="ChangeDiscountType()" required>
              <option value="" ng-hide="item.DiscountType">Please Select a Discount Type</option>
            </select>
          </div>

          <div class="form-group" ng-show="item.DiscountType.DiscountSourceType === 1">
            <label for="Staff">Staffs</label>
            <select name="Staff" id="Staff" class="form-control" ng-options="staff.Id as staff.Name for staff in Staffs" ng-model="item.SourceReference">
              <option value="" ng-hide="item.SourceReference">Please Select a Staff</option>
            </select>
          </div>

          <div class="form-group" ng-show="item.DiscountType.DiscountSourceType === 2">
            <label for="Client">Clients</label>
            <select name="Client" id="Client" class="form-control" ng-options="client.Id as client.Name for client in Clients" ng-model="item.SourceReference">
              <option value="" ng-hide="item.SourceReference">Please Select a Client</option>
            </select>
          </div>

          <div class="form-group" ng-class="{ 'has-error': errors.Amount}">
            <label for="Amount">Amount</label>
            <input type="text" name="Amount" class="form-control" id="" placeholder="Input field" ng-model="item.Amount">
            <error-widget field="errors.Amount"></error-widget>
          </div>

          <div class="form-group" ng-class="{ 'has-error': errors.Percentage}">
            <label for="Percentage">Percentage</label>
            <input type="text" name="Percentage" class="form-control" id="" placeholder="Input field" ng-model="item.Percentage">
            <error-widget field="errors.Percentage"></error-widget>
          </div>

          <div class="form-group" ng-class="{ 'has-error': errors.PublishedInTermNumber}">
            <label for="PublishedInTermNumber">Published In Term Number</label>
            <input type="text" name="PublishedInTermNumber" class="form-control" id="" placeholder="Input field" ng-model="item.PublishedInTermNumber">
            <error-widget field="errors.PublishedInTermNumber"></error-widget>
          </div>

          <div class="form-group" ng-class="{ 'has-error': errors.PublishedInTermYear}">
            <label for="PublishedInTermYear">Published In Term Year</label>
            <input type="text" name="PublishedInTermYear" class="form-control" id="" placeholder="Input field" ng-model="item.PublishedInTermYear">
            <error-widget field="errors.PublishedInTermYear"></error-widget>
          </div>

          <div class="form-group" ng-class="{ 'has-error': errors.IssuedByCourseType}">
            <label for="IssuedByCourseType">Issued by Course Type (GE, YL, KK) - empty if you're not sure</label>
            <input type="text" name="IssuedByCourseType" class="form-control" id="" placeholder="Input field" ng-model="item.IssuedByCourseType">
            <error-widget field="errors.IssuedByCourseType"></error-widget>
          </div>

          <div class="form-group" ng-class="{ 'has-error': errors.errors.ValidFrom}">
            <label for="">Start Date</label>
            <div class="input-group" ng-click="openDatepicker($event, 0)">
              <input type="hidden" class="form-control" datepicker-popup="{{format}}" ng-model="item.ValidFrom" is-open="datePicker.isOpen[0]" datepicker-options="dateOptions" close-text="Close" ng-disabled="true" />
              <input type="text" class="form-control" ng-disabled="true" ng-value="item.ValidFrom | date: 'dd MMMM yyyy'">
              <span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
            </div>
            <error-widget field="errors.errors.ValidFrom"></error-widget>
          </div>

          <div class="form-group" ng-class="{ 'has-error': errors.errors.ValidUntil}">
            <label for="">End Date</label>
            <div class="input-group" ng-click="openDatepicker($event, 1)">
              <input type="hidden" class="form-control" datepicker-popup="{{format}}" ng-model="item.ValidUntil" is-open="datePicker.isOpen[1]" min-date="item.ValidFrom" datepicker-options="dateOptions" close-text="Close" ng-disabled="true" />
              <input type="text" class="form-control" ng-disabled="true" ng-value="item.ValidUntil | date: 'dd MMMM yyyy'">
              <span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
            </div>
            <error-widget field="errors.errors.ValidUntil"></error-widget>
          </div>

          <div class="form-group" ng-class="{ 'has-error': errors.Note}">
            <label for="Note">Note</label>
            <input type="text" name="Note" class="form-control" id="" placeholder="Input field" ng-model="item.Note">
            <error-widget field="errors.Note"></error-widget>
          </div>

          <button type="submit" class="btn btn-primary" >Submit</button>
        </form>
      </div>
    </div>

  </div>
</div>